package clientP;


import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;

/**
 *
 * @author Sandro
 */
public class MenuClient {

        private JFrame jf;
        private JLabel ipLabel;
        private JTextField ip;
        private JLabel gameLabel;
        private JTextField gameName;
        private JLabel userLabel;
        private JTextField userName;
        private JLabel gameStatus;
        private JButton startGame;
        private JButton stopServer;

    public MenuClient(final Client c){
        super();
        jf=new JFrame("Ciente Vidas");
        jf.setBounds(100,100,420,200);
       
        jf.getContentPane().setLayout(null);

        ipLabel = new JLabel();
        ipLabel.setBounds(50,10,50,20);
        jf.getContentPane().add(ipLabel);
        ipLabel.setText("IP:");

        ip = new JTextField();
        ip.setBounds(100,10,100,20);
        jf.getContentPane().add(ip);

        userLabel = new JLabel();
        userLabel.setBounds(50,40,50,20);
        jf.getContentPane().add(userLabel);
        userLabel.setText("Usuario:");
        
        userName = new JTextField();
        userName.setBounds(100,40,100,20);
        jf.getContentPane().add(userName);
        userName.setText("Jugador");// Nombre de juegador por defecto

        gameLabel = new JLabel();
        gameLabel.setBounds(50,70,50,20);
        jf.getContentPane().add(gameLabel);
        gameLabel.setText("Juego:");

        gameName = new JTextField();
        gameName.setBounds(100,70,100,20);
        jf.getContentPane().add(gameName);
        gameName.setText("Juego");// Nombre de juegador por defecto

        gameStatus = new JLabel();
        gameStatus.setBounds(50,100,300,20);
        jf.getContentPane().add(gameStatus);
        gameStatus.setText("Estado:  No conectado");

        startGame=new JButton("Iniciar");
        startGame.setBounds(50,130,100,20);
        jf.getContentPane().add(startGame);

        stopServer=new JButton("Salir");
        stopServer.setBounds(270,130,100,20);
        jf.getContentPane().add(stopServer);

        /*Varias Clases anónimas para conectar a la interface gráfica*/
        /*Este clase anónima se invoca cuando se presiona salir el juego*/
        stopServer.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent e) {System.exit(0);}});

        /*Esta clase anónima se invoca cuando se presiona apagar el server*/
        startGame.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent e){
                setStartGameEnabled(false);
                c.setUserName(getUserName());
                setUserName(getUserName());
                c.registrarEnServer();
               }});

        jf.setVisible(true);
    }


     public String getGameName(){
       return this.gameName.getText();
      }

     public String getUserName(){
       return this.userName.getText();
      }

     public String getIp(){
       return this.ip.getText();
      }

      public void setUserName(String user){
        this.userName.setText(user);
      }
      public void setSatus(String s){
        this.gameStatus.setText("Estado:  "+s);
      }

      public void setGameName(String name) {
        this.gameName.setText(name);
      }

      public void setIp(String ipS) {
        this.ip.setText(ipS);
      }

      public void setStartGameEnabled(boolean t){
        startGame.setEnabled(t);
      }
      
}
